/**
 *
 */
package com.ssyt.examinationsystem.dao.impl;

import com.jdbc.util.JdbcUtils;
import com.ssyt.examinationsystem.dao.IRuleInfoDAO;
import com.ssyt.examinationsystem.entity.RuleInfo;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class RuleInfoDAOImpl implements IRuleInfoDAO {

    @Override
    public int handPacking(RuleInfo rule) {
        String sql = "insert into ruleInfo(ruleId,scScore,scIds,mulScore,"
                + "mulIds,bkScore,bkIds,jdScore,jdIds,subScore,subIds,totalScore,testType) "
                + "values(null,?,?,?,?,?,?,?,?,?,?,?,1)";

        Object[] parameters = {rule.getScScore(), rule.getScIds(), rule.getMulScore(), rule.getMulIds(),
                rule.getBkScore(), rule.getBkIds(), rule.getJdScore(), rule.getJdIds(), rule.getSubScore(),
                rule.getSubIds(), rule.getTotalScore()

        };

        return JdbcUtils.executeUpdate(sql, parameters);
    }

    @Override
    public int autoPacking(RuleInfo rule) {
        String sql = "insert into ruleInfo(ruleId,scNumber,scScore,mulNumber,mulScore,"
                + "bkNumber,bkScore,jdNumber,jdScore,subNumber,subScore,totalScore,testType) "
                + "values(null,?,?,?,?,?,?,?,?,?,?,?,2)";

        Object[] parameters = {rule.getScNumber(), rule.getScScore(), rule.getMulNumber(), rule.getMulScore(),
                rule.getBkNumber(), rule.getBkScore(), rule.getJdNumber(), rule.getJdScore(), rule.getSubNumber(),
                rule.getSubScore(), rule.getTotalScore()

        };

        return JdbcUtils.executeUpdate(sql, parameters);
    }

    @Override
    public List<Map<String, Object>> getRules() {
        String sql = "select * from ruleinfo";
        return JdbcUtils.executeQuery(sql);
    }

    @Override
    public int deleteRule(String ruleId) {
        String sql = "delete from ruleinfo where ruleid=?";
        return JdbcUtils.executeUpdate(sql, ruleId);
    }

    @Override
    public int updateRule(RuleInfo rule) {
        String sql = "update ruleinfo set scNumber=?,scScore=?,scIds=?,mulNumber=?,"
                + "mulScore=?,mulIds=?,bkNumber=?,bkScore=?,bkIds=?,jdNumber=?,jdScore=?,jdIds=?,subNumber=?,"
                + "subScore=?,subIds=?,testType=?,totalScore=? where ruleId=?";
        Object[] parameters = {rule.getScNumber(), rule.getScScore(), rule.getScIds(), rule.getMulNumber(),
                rule.getMulScore(), rule.getMulIds(), rule.getBkNumber(), rule.getBkScore(), rule.getBkIds(),
                rule.getJdNumber(), rule.getJdScore(), rule.getJdIds(), rule.getSubNumber(), rule.getSubScore(),
                rule.getSubIds(), rule.getTestType(), rule.getTotalScore(), rule.getRuleId()};
        return JdbcUtils.executeUpdate(sql, parameters);
    }

    @Override
    public int addRule(RuleInfo rule) {
        String sql = "insert into ruleInfo(ruleId,scNumber,scScore,scIds,mulNumber,mulScore,"
                + "mulIds,bkNumber,bkScore,bkIds,jdNumber,jdScore,jdIds,subNumber,subScore,subIds,totalScore,testType) "
                + "values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        Object[] parameters = {rule.getScNumber(), rule.getScScore(), rule.getScIds(), rule.getMulNumber(),
                rule.getMulScore(), rule.getMulIds(), rule.getBkNumber(), rule.getBkScore(), rule.getBkIds(),
                rule.getJdNumber(), rule.getJdScore(), rule.getJdIds(), rule.getSubNumber(), rule.getSubScore(),
                rule.getSubIds(), rule.getTotalScore(), rule.getTestType()

        };
        return JdbcUtils.executeUpdate(sql, parameters);
    }

    /* (non-Javadoc)
     * @see com.ssyt.examinationsystem.dao.IRuleInfoDAO#getRuleInfoById(java.lang.String)
     */
    @Override
    public Map<String, Object> getRuleInfoById(String ruleId) {
        String sql = "select * from ruleInfo where ruleId = ?";
        List<Map<String, Object>> list = JdbcUtils.executeQuery(sql, ruleId);

        return list != null && list.size() > 0 ? list.get(0) : null;
    }

}
